package com.yuchen.ishop.web;

import org.springframework.ui.ModelMap;
import org.apache.commons.lang.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Jack Q
 */
public class BaseAction {

    public Map successJson(String msg){
        Map map = new HashMap(2);
        map.put("success",true);
        map.put("msg",msg);
        return map;
    }
    public Map successJson(){
        return successJson(null);
    }

    public Map<String,Object> convertParameterMap(Map<String,String[]> parameterMap){
        if(parameterMap!=null&&parameterMap.size()>0){
            Map map = new HashMap(parameterMap.size());
            String val = "";
            for(Map.Entry<String,String[]> param : parameterMap.entrySet()){
                val = StringUtils.join(param.getValue(),",");
                if(StringUtils.isBlank(val))continue;
                map.put(param.getKey(), val);
            }
            return map;
        }
        return null;
    }

}
